<template>
  <!-- <div id="nav">
    <router-link to="/">Home</router-link> |
    <router-link to="/about">About</router-link>
  </div> -->
  <router-view />
  <!-- <transition name="van-fade">
		<keep-alive include="case,manage,fans">
			<router-view/>
		</keep-alive>
	</transition> -->
</template>

<script>
export default {
  mounted() {
    const _this = this;
    console.log("wrapperApp");
    // const selectedCampus = JSON.parse(localStorage.getItem("selectedCampus"));
    // if (selectedCampus && selectedCampus.id) {
    // } else {
    //   this.$router.push("/selectCampus");
    // }
    // _this.getWeixinConfig();
    // const openid = localStorage.getItem('openid')
    // const userInfo = localStorage.getItem('userInfo')
    // if(!openid&&!userInfo){
    // 	_this.getWeixinConfig();
    // }
  },
  methods: {
    getWeixinConfig() {
      const _this = this;
      let params = {};
      _this.$request.getWeixinConfig(params).then((res) => {
        // alert("getWeixinConfig:"+JSON.stringify(res))
        _this.$store.commit("setAppid", res.data.value.appid);
        _this.$store.commit("setSecret", res.data.value.secret);
        //_this.getCode(res.data.value.appid)
        if (process.env.NODE_ENV == "production") {
          _this.getCode(res.data.value.appid);
        }
      });
    },
    getCode(appid) {
      // 非静默授权，第一次有弹框
      const _this = this;
      const code = this.getUrlParam("code"); // 截取路径中的code，如果没有就去微信授权，如果已经获取到了就直接传code给后台获取openId
      const local = window.location.href;
      if (code == null || code === "") {
        window.location.href =
          "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" +
          appid +
          "&redirect_uri=" +
          encodeURIComponent(local) +
          "&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect";
      } else {
        _this.$store.commit("setCode", code);
        // alert(('setCode:'+code))
        _this.getOpenId(code); //把code传给后台获取用户信息
      }
    },
    getUrlParam(name) {
      var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
      var r = window.location.search.substr(1).match(reg);
      if (r != null) return unescape(r[2]);
      return null;
    },
    getFansItem(item) {
      const _this = this;
      let params = {
        openid: item.openid,
        nickname: item.nickname,
        name: item.nickname,
        avatar: item.avatar,
        province: item.province,
        city: item.city,
      };
      _this.$request.MemberH5Item(params).then((res) => {
        //默认
      });
    },
    getOpenId(code) {
      const _this = this;
      let params = {
        appid: _this.$store.state.appid,
        secret: _this.$store.state.secret,
        code: code,
      };
      _this.$request.getOpenid(params).then((res) => {
        const userInfo = res.data[0];
        const openid = userInfo["openid"];
        const nickname = userInfo["nickname"];
        const headimgurl = userInfo["headimgurl"];
        const province = userInfo["province"];
        const city = userInfo["city"];
        _this.$store.commit("setOpenid", openid);
        console.log("openid", openid);
        if (openid) {
          localStorage.setItem("openid", openid);
        }
        // alert("openid:"+openid)
        const item = {
          openid,
          nickname,
          avatar: headimgurl,
          province,
          city,
          name: nickname,
        };
        localStorage.setItem("userInfo", JSON.stringify(item));
        localStorage.setItem("myInfo", JSON.stringify(item));
        _this.$store.commit("setUserInfo", item);
      });
    },
  },
};
</script>


<style lang="scss">
@import "@/assets/css/variable";
html {
  font-size: 10px !important;
  min-height: 100%;
}
@media only screen and (max-width: 374px) {
  /* iphone5 或者更小的尺寸，以 iphone5 的宽度（320px）比例设置 font-size */
  html {
    font-size: 10px !important;
  }
}
@media only screen and (min-width: 375px) and (max-width: 413px) {
  /* iphone6/7/8 和 iphone x */
  html {
    font-size: 11px !important; // 1rem=11px
  }
}
@media only screen and (min-width: 414px) {
  /* iphone6p 或者更大的尺寸，以 iphone6p 的宽度（414px）比例设置 font-size */
  html {
    font-size: 12px !important; // 1rem=12px
  }
}
@media only screen and (min-width: 768px) {
  /* iphone6p 或者更大的尺寸，以 iphone6p 的宽度（414px）比例设置 font-size */
  html {
    font-size: 16px !important; // 1rem=16px
  }
}

// html {
// 	@media only screen and (min-width: 413px) {
// 	    /* iphone6p 或者更大的尺寸，以 iphone6p 的宽度（414px）比例设置 font-size */
// 	    font-size: 12px !important;
// 	}
// 	@media only screen and (min-width: 768px) {
// 	    /* iphone6p 或者更大的尺寸，以 iphone6p 的宽度（414px）比例设置 font-size */
// 	    font-size: 16px !important;
// 	}
// }

html {
  display: flex;
  flex-direction: column;
}
body {
  flex: 1;
  display: flex;
  flex-direction: column;
}
.wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
}
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100%;
  box-sizing: border-box;
  letter-spacing: 1px;
}
img,
iframe {
  width: 100%;
}
.detail_tabs {
  .van-cell {
    background-color: #e5e5e5 !important;
  }
}
p {
  margin-bottom: 0 !important;
}
.load-more {
  text-align: center;
  background-color: white;
  border: 1px solid #e2e2e2;
  border-radius: 0.8rem;
  box-sizing: border-box;
}
.no-data {
  text-align: center;
}
.d-none {
  display: none;
}
.padding-all {
  padding: 0.8rem;
}
.padding-all-m {
  padding: 1.4rem;
}
.padding-all-l {
  padding: 1.7rem;
}
.padding-lr {
  padding-left: 0.8rem;
  padding-right: 0.8rem;
}
.padding-lr-l {
  padding-left: 1.6rem;
  padding-right: 1.6rem;
}
.border-r-l {
  border-radius: 0.8rem;
}
.border-r-m {
  border-radius: 0.6rem;
}
.color-blue {
  color: blue;
}
.color-red {
  color: red;
}
.color-green {
  color: green;
}
.color-ll {
  color: #111;
}
.color-l {
  color: #333;
}
.color-m {
  color: #666;
}
.color-s {
  color: #999;
}
.margT-s {
  margin-top: 0.3rem;
}
.margT-m {
  margin-top: 0.4rem;
}
.margT-ll {
  margin-top: 4rem;
}
.margT-l {
  margin-top: 1rem;
}
.margL-s {
  margin-left: 0.3rem;
}
.margL-m {
  margin-left: 0.6rem;
}
.margL-l {
  margin-left: 1rem;
}
.margR-l {
  margin-right: 1rem;
}
.margB-ll {
  margin-bottom: 1.6rem;
}
.margB-l {
  margin-bottom: 1rem;
}
.margB-m {
  margin-bottom: 0.6rem;
}
.titleMoreBox {
  padding: 2rem 1.8rem 0 1.8rem;
  display: flex;
  align-items: center;
  justify-content: space-between;

  .title {
    font-size: 1.6rem;
    font-weight: bold;
  }

  .more {
    display: flex;
    align-items: center;
    color: #999999;
  }
}
.t-center {
  text-align: center;
}
.t-bold {
  font-weight: bold;
}
.tabbar-height {
  height: 50px;
  width: 100%;
  background-color: $main-bgc;
}
.tabbar-height-white {
  height: 50px;
  width: 100%;
  background-color: $main-bgc-white;
}
.line-height-m {
  line-height: 1.3em;
}
.line-height-l {
  line-height: 1.5em;
}
.splitLine {
  width: 100%;
  height: 1em;
  background-color: $main-bgc;
}
.main-bg-gray {
  background-color: $main-bgc;
}
.main-bg-white {
  background-color: $main-bgc-white;
}
.main-bg {
  background-color: $main-bgc;
}
.title-l {
  font-size: 1.8rem;
  font-weight: bold;
  color: #111;
}
.title-m {
  font-size: 1.6rem;
  font-weight: bold;
  color: #222;
}
.title-s {
  font-size: 1.4rem;
  font-weight: bold;
  color: #333;
}
.fs-12 {
  font-size: 1.2rem;
}
.fs-13 {
  font-size: 1.3rem;
}
.fs-14 {
  font-size: 1.4rem;
}
.fs-15 {
  font-size: 1.5rem;
}
.fs-16 {
  font-size: 1.6rem;
}
.fs-18 {
  font-size: 1.8rem;
}
</style>
